package com.bxd.baodan.logic;

import com.bxd.baodan.activity.BaseActivity;
import com.bxd.baodan.util.LogUtil;
import com.bxd.baodan.util.StringUtil;

/**
 * Created by lizhichao on 17/8/31.
 */

public class DesignStep {


    private BaseActivity activity;

    //step1
    public String gender;
    public String age;
    public int preAge = -1;
    public String role;

    //step2
    public String career;  //职业
    public String personal_annual_income;//年收入

    //step3
    public String life_tag; //生活状态

    //step4_1
    public String have_social_insurance;  //有社保
    public String have_business_insurance;//是否有其他商保




    //step4_2
    public String business_insurance_life;//人寿
    public String business_insurance_serious;
    public String business_insurance_accident;
    public String business_insurance_medical;
    public String business_insurance_pension;
    public String business_insurance_education;

    //step5
    public String family_annual_income;
    public String family_month_spending;
    public String family_month_alimony;
    public String family_loan;

    //step6
    public String education_plan;
    public String family_member;//家庭成员

    public String roleText;
    public boolean isEnd;




    public int checked_gender_id;

    public DesignStep(BaseActivity activity) {
        this.activity = activity;
    }



    public boolean nextStep(int currentStep, boolean isMember) {
        // TODO: 17/9/3 现在只能写一个大致的规则 ,不能太细,要调

       LogUtil.e("个人数据: " + "\n"+toString());

        isEnd = false;
        if (currentStep == 0) {
            return setAge();

        } else {
            if (StringUtil.isEmpty(age)) {
                return false;
            }
            int age_ = Integer.parseInt(age);
            if (age_ < 18) {
                if (isMember) {
                    return step_0_18_member(currentStep);
                } else {
                    return step_0_18(currentStep);
                }

            } else if (age_ > 17 && age_ < 56) {
                if (isMember) {
                    return step_18_55_member(currentStep);
                } else {
                    return step_18_55(currentStep);
                }


            } else {

                if (isMember) {
                    return step_55_member(currentStep);
                } else {
                    return step_55_(currentStep);
                }


            }
        }
    }

    private boolean step_55_(int currentStep) {

        switch (currentStep) {
            case 0:
                return setAge();
            case 1:
                return setJob();

            case 2:

                return setLifeTag();


            case 3:

                return  setSheBao();
            case 4:
                isEnd = true;
                return  setFamIncome();

        }
        return false;
    }


    private boolean step_55_member(int currentStep) {
        switch (currentStep) {
            case 0:
                return setAge();
            case 1:
                return  setJob();
            case 2:
                return setLifeTag();

            case 3:
                isEnd = true;
                return setSheBao();




        }
        return false;
    }


    private boolean step_18_55(int currentStep) {
        switch (currentStep) {
            case 0:
                return  setAge();
            case 1:
                return  setJob();
            case 2:
                return  setLifeTag();
            case 3:
                return  setSheBao();
            case 4:
                return setMember();

            case 5:
                isEnd = true;
                return  setFamIncome();
        }
        return false;
    }


    private boolean step_18_55_member(int currentStep) {
        switch (currentStep) {
            case 0:
                return   setAge();
            case 1:
                return  setJob();
            case 2:
                return setLifeTag();

            case 3:
                isEnd = true;
                return  setSheBao();

        }
        return false;
    }

    private boolean step_0_18(int currentStep) {

        switch (currentStep) {
            case 0:
                return  setAge();
            case 1:

                return setFamIncome();

            case 2:
                return  setSheBao();


            case 3:
                isEnd = true;

                return setStudy();

        }


        return false;
    }


    private boolean step_0_18_member(int currentStep) {

        switch (currentStep) {
            case 0:
                return setAge();

            case 1:
                return setSheBao();


            case 2:
                isEnd = true;
                return setStudy();
        }


        return false;
    }

    private boolean setAge() {
        if (StringUtil.isEmpty(gender)) {
           // activity.showToast("请选择性别");
            activity.showToast("请完善信息");
            return false;
        }
        if (StringUtil.isEmpty(age)) {
           // activity.showToast("请填写年龄");
            activity.showToast("请完善信息");
            return false;
        }
        if (Integer.parseInt(age) < 0 || Integer.parseInt(age) > 120) {
            activity.showToast("请输入0~120之间的数字");
            return false;
        } else {
            return true;
        }
    }

    public boolean setJob() {
        if (StringUtil.isEmpty(career)) {
           // activity.showToast("请选择职业");
            activity.showToast("请完善信息");
            return false;
        }
        if (StringUtil.isEmpty(personal_annual_income)) {
          //  activity.showToast("请完善信息");
            activity.showToast("请填写年收入");
            return false;
        }
        return true;
    }

    public boolean setLifeTag() {
        // FIXME: 2017/12/8 不做限制
//        if (StringUtil.isEmpty(life_tag)) {
//          //  activity.showToast("请选择生活状态");
//            activity.showToast("请完善信息");
//            return false;
//        }
        return true;
    }

    private boolean setSheBao() {

        if (StringUtil.isEmpty(have_social_insurance)) {
           // activity.showToast("请选择是否有社保");
            activity.showToast("请完善信息");
            return false;
        }
        if (StringUtil.isEmpty(have_business_insurance)) {
          //  activity.showToast("请选择是否有其它社保");
            activity.showToast("请完善信息");
            return false;
        }

        if (have_business_insurance.equals("have")) {

            String[] others = {business_insurance_life,business_insurance_serious,
                    business_insurance_medical, business_insurance_pension,
                    business_insurance_education, business_insurance_accident};

            for (String str : others
                    ) {
                if (!StringUtil.isEmpty(str)) {

                    return true;
                }
            }

            activity.showToast("至少填写一种保险费用");

            return false;

        }


        return true;

    }

    private boolean setFamIncome() {

        String[] famIncomes = {family_annual_income, family_month_spending, family_month_alimony, family_loan};
        int age_ = Integer.parseInt(age);
        for (String famIncome : famIncomes) {

            if (age_ < 18) {
                if (StringUtil.isEmpty(famIncomes[0])) {
                    activity.showToast("请完善信息");
                    return false;
                } else {
                    return true;
                }


            } else {
                if (StringUtil.isEmpty(famIncomes[0]) || StringUtil.isEmpty(famIncomes[1])) {
                    // activity.showToast("请填写家庭开支");
                    activity.showToast("请完善信息");
                    return false;
                } else {
                    return true;
                }

            }


        }

        return true;
    }


    private boolean setMember() {
        if (StringUtil.isEmpty(family_member)) {

            //activity.showToast("请选择家庭成员");
            activity.showToast("请完善信息");
            return false;
        }


        return true;

    }

    private boolean setStudy() {
        if (StringUtil.isEmpty(education_plan)

                ) {
          //  activity.showToast("请选择教育计划");
            activity.showToast("请完善信息");
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "DesignStep{" +
                "gender='" + gender + '\'' +
                ", age='" + age + '\'' +
                ", preAge=" + preAge +
                ", role='" + role + '\'' +
                ", career='" + career + '\'' +
                ", personal_annual_income='" + personal_annual_income + '\'' +
                ", life_tag='" + life_tag + '\'' +
                ", have_social_insurance='" + have_social_insurance + '\'' +
                ", have_business_insurance='" + have_business_insurance + '\'' +
                ", business_insurance_life='" + business_insurance_life + '\'' +
                ", business_insurance_serious='" + business_insurance_serious + '\'' +
                ", business_insurance_accident='" + business_insurance_accident + '\'' +
                ", business_insurance_medical='" + business_insurance_medical + '\'' +
                ", business_insurance_pension='" + business_insurance_pension + '\'' +
                ", business_insurance_education='" + business_insurance_education + '\'' +
                ", family_annual_income='" + family_annual_income + '\'' +
                ", family_month_spending='" + family_month_spending + '\'' +
                ", family_month_alimony='" + family_month_alimony + '\'' +
                ", family_loan='" + family_loan + '\'' +
                ", education_plan='" + education_plan + '\'' +
                ", family_member='" + family_member + '\'' +
                ", roleText='" + roleText + '\'' +
                ", isEnd=" + isEnd +
                ", checked_gender_id=" + checked_gender_id +
                '}';
    }
}
